﻿
using System.Windows;
using MyFloridaHouse.libSvUtilities;
using System.IO;
using System;
using MyFloridaHouse.libSvOpenDistricts.Dialogs;
namespace MyFloridaHouse.libSvOpenDistricts.ViewModel
{
    public partial class ViewModelBase
    {
        private bool CmdFileImportCanExecute(object parameter)
        {
            return true;
        }


        private void CmdFileImportExecute(object parameter)
        {
            // ask for confirmation if a plan exists
            if (districtPlan.districtCount > 0)
            {
                PlanOverwriteConfirmDlg planOverwriteConfirmDlg = new PlanOverwriteConfirmDlg(OnMemberPropertyChanged, DisplayPanelForDialogs);
                planOverwriteConfirmDlg.Start(StartFileImportLocal);
            }
            else
            {
                StartFileImportLocal(true);
            }
        }

        private void StartFileImportLocal(bool result)
        {
            if (result)
            {
                FileStream fileStream = null;
                try
                {

                    string filter = "";
                    FileInfo fileInfo;

                    districtPlan.SetupFileImport(out filter);
                    if (LocalFileManager.ReadFileLocal(filter, out fileInfo, out fileStream))
                    {
                        if (fileInfo != null)
                        {
                            DistrictPlanLoadFile(fileStream, fileInfo.Extension);
                        }

                    }
                }
                catch (Exception ex)
                {
                }
            }
        }


    }
}
